// export function doAnimation  (){
//     const observer = new IntersectionObserver((entries) => {
//         entries.forEach(entry => {
//             if (entry.isIntersecting) {
//                 if(!entry.target.classList.contains("jump-in-left")){
//                     entry.target.classList.add('jump-in-left'); // 进入视口时添加动画类
//                 }
//             } else {
//                 entry.target.classList.remove('jump-in-left'); // 离开时可选移除
//             }
//         });
//     }, { threshold: 0.1 });
//
//     const elements = document.getElementsByClassName("animation-jump-in-left");
//     if(elements){
//         for (let element of elements) {
//             observer.observe(element);
//         }
//     }
// }
const animationList =[
    {name:"animation-jump-in-left",
        observer:new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    if(!entry.target.classList.contains("jump-in-left")){
                        entry.target.classList.add('jump-in-left'); // 进入视口时添加动画类
                    }
                } else {
                    entry.target.classList.remove('jump-in-left'); // 离开时可选移除
                }
            });
        }, { threshold: 0.1 })
    },{name:"animation-jump-in-right",
        observer:new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    if(!entry.target.classList.contains("jump-in-right")){
                        entry.target.classList.add('jump-in-right'); // 进入视口时添加动画类
                    }
                } else {
                    entry.target.classList.remove('jump-in-right'); // 离开时可选移除
                }
            });
        }, { threshold: 0.1 })
    },{name:"animation-rotate-in",
        observer:new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    if(!entry.target.classList.contains("rotate-in")){
                        entry.target.classList.add('rotate-in'); // 进入视口时添加动画类
                    }
                } else {
                    entry.target.classList.remove('rotate-in'); // 离开时可选移除
                }
            });
        }, { threshold: 0.1 })
    },{name:"animation-bounce-in",
        observer:new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    if(!entry.target.classList.contains("bounce-in")){
                        entry.target.classList.add('bounce-in'); // 进入视口时添加动画类
                    }
                } else {
                    entry.target.classList.remove('bounce-in'); // 离开时可选移除
                }
            });
        }, { threshold: 0.1 })
    }


    ];

export function doAnimation  (){
    for (let item of animationList) {
        const elements = document.getElementsByClassName(item.name);
        if(elements){
            for (let element of elements) {
                item.observer.observe(element);
            }
        }
    }
}
